home *** CD-ROM | disk | FTP | other *** search
- DEFINT A-Z ' everything about integers is faster and memory saving.
- ' this makes all the variables integers unless you
- ' specify them as another type
-
- '----------------------------------------------------------------------
- ' ISAMTOOT.L1 - Source Code for Lesson #1 of ISAMTOOT
- '----------------------------------------------------------------------
-
-
- TYPE lesson1data ' defining the fields of our first database.
- name AS STRING * 35
- address AS STRING * 35
- cityStateZip AS STRING * 35
- END TYPE
-
- DIM lesson1record AS lesson1data ' creating the memory block for a database
- ' record, dimensioning the database.
-
- ' now we open the database. You will see later that several files -- MS
- ' calls them Tables -- can be in the same physical disk file. Many other
- ' data management systems create two disk files for each "file," an index
- ' AND a datafile -- that can lead to real file polution in a multi-file
- ' relational application. ISAM can put 13 into ONE physical disk enity
- ' and let it grow up to 128 MEGabytes.
-
- OPEN "lesson1.MDB" FOR ISAM lesson1data "lesson1table" AS #1
-
- ' This would be the logical place to create an index or indexES for
- ' this file. ISAM creates one index itself -- it keeps track of the
- ' order in which the records were added to the file. In the interest
- ' of simplicity, we will use this "internal" ISAM index. If you don't
- ' specify an index, ISAM uses this one.
-
- ' Now we are ready to add data to this database. LINE INPUT is a "bad"
- ' programming practice in that you surrender control to the operator and
- ' don't have any control over the amount of data they type in, but it is
- ' entirely adequate for the purpose we intend.
- '
- ' YOU know that there are only 35 spaces available for each of the
- ' three fields and ISAM will lop off any excess.
- '
- ' We set up a simple DO/LOOP structure to gather the information we
- ' want and while it's a good programming process to swap database fields
- ' in and out of "work" fields -- sort of a electronic scratch pad --
- ' we will directly enter the fields in this lesson.
- '
- ' ISAM -- by virtue of the dimensioning statement -- knows these fields
- ' as lesson1record.[name of the field]. In a "real" application, you
- ' will likely opt for more cryptic name(s) to reduce the amount of typing
- ' you would have to do. The TYPE needing a period in the name is reason
- ' enough to take MS's lead in using UpperAndLower case to name your
- ' variables rather than periods, dashes, underscores, etc.
-
- DO
-
- CLS ' just clear the screen for fresh workspace
-
- ' the LOF() function, in ISAM, reports the
- ' number of records in the file, rather than
- ' the total number of bytes.
-
- PRINT , , "There are "; LOF(1); " records in the file."
- PRINT
- PRINT , : LINE INPUT "First & Last Name: "; lesson1record.name
- PRINT , : LINE INPUT " Address: "; lesson1record.address
- PRINT , : LINE INPUT "City, State & Zip: "; lesson1record.cityStateZip
- PRINT
- ' The operator has entered the data, now we
- ' let them decide what to do with it
- '
- ' TONS of code are written to get and control
- ' input . . . this is a VERY minimal approach.
-
- PRINT , "<S>ave - <E>dit - <Q>uit"
- PRINT , " Touch S or E or Q"
-
- ' this next line makes sure we get an upper case entry . . .
- ' dataDecision$ lends itself to being shortened to: dd$
-
- dataDecision$ = UCASE$(INPUT$(1))
-
- ' A SELECT CASE / END SELECT block is a far better way to deal
- ' with action options the operator has. We will use it in later
- ' lessons, but, for now, IF's will do what we need done.
-
- IF dataDecision$ = "S" THEN
- INSERT #1, lesson1record ' we save the record.
- LOCATE 25, 40: PRINT " Saved "; ' and let the operator know.
- SLEEP 1 ' a moment to read the saved message
- EXIT DO
- END IF
-
- LOOP UNTIL dataDecision$ = "Q"
-
- CLS
- PRINT
- PRINT , "Total records now in the file: "; LOF(1)
- PRINT
- PRINT , "Now, we report the contents of the file . . . "
- PRINT
-
- ' To report the contents of an ISAM file, there are three steps:
- ' 1. Set the index ISAM should use.
- ' 2. Move to the first record that matches selection criterion.
- ' 3. Retrieve that record.
- '
- ' For this first lesson, we won't specify any index, so ISAM will use
- ' the one it created when it stored the data. We also are not picky about
- ' the particular record we want -- we want to see EVERYTHING we put in --
- ' so we'll just move to the first record and march through the file.
- '
- ' The DO UNTIL EOF is a useful device to make sure we step through the
- ' whole file.
- '
- MOVEFIRST #1
-
- DO UNTIL EOF(1)
- RETRIEVE #1, lesson1record ' the data moves into memory.
- PRINT , lesson1record.name ' and we specify what parts
- PRINT , lesson1record.address ' of that record we want to
- PRINT , lesson1record.cityStateZip ' display on the screen
- PRINT , "------------------------------------------"
- SLEEP 1 ' slows things down.
- MOVENEXT #1 ' step forward one record
- LOOP
-
- PRINT
- PRINT , "We've reached the end of the file."
- PRINT
- PRINT , "Press Shift+F5 to restart, enter a"
- PRINT , "record and report file contents."
- PRINT
- PRINT
-
-
- END ' lesson 1 source code ends
-
-
-
-